<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>你好，总账号</title>
  <script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/jquery"></script>
  <script src="__PUBLIC__/script/layer/layer.js"></script>
  <script src="__PUBLIC__/node_modules/datatables/media/js/jquery.dataTables.min.js"></script>
  <script src="__PUBLIC__/script/bootstrap-treeview-master/dist/bootstrap-treeview.min.js"></script>
  <link rel="stylesheet" href="__PUBLIC__/script/bootstrap-treeview-master/dist/bootstrap-treeview.min.css">
  <link rel="stylesheet" href="__PUBLIC__/node_modules/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="__PUBLIC__/style/manage.css">
  <style>
    .authSetting #fuck {
      pointer-events: none;
    }
  </style>
</head>
<body>
  <div class="container-fluid">
    <div class="row">
      <header class="col-xs-6 col-md-2 account_name"><img class='img-responsive' src="__PUBLIC__/images/logo_long.jpg" alt=""></header>
      <div class="col-xs-12 col-md-12">
        <div class="row">

          <!-- 左侧栏 -->
          <div class="col-md-2 manage_nav_box">
              <iframe src="{:U('Wxauthorise/nav_1')}?local=weixin_m" frameborder="0" width="100%" style="height:35rem;"></iframe>
              <!-- 账号选项 -->
              <div class="account_option">
                <a href="{:U('index/update_passwd')}" class="pass_mod">修改密码</a>
                <a href="{:U('index/loginout')}" class="sign_out">退出登录</a>
              </div>
              <!-- end 账号选型 -->
          </div>
          <!-- end 左侧栏 -->

          <!-- 右主体  -->
          <div class="col-md-10 col-md-10 messageBox">
            <!-- 账号主体显示 -->
            <!-- <div class="account_name">金融公司名称</div> -->
            <!-- end 账号主体显示 -->

            <!-- begin  授权地区列表列表 -->
            <header style='min-height:3.5rem;'>所有公众号列表<a href="#"><img id="add_local_frame" src="__PUBLIC__/images/neiye/u138.png" alt="u138" title="添加授权地区"></a></header>
            <!-- end 表头 -->

            <table class="messageBoxContent table table-striped table-bordered" id="main_table">
                <thead>
                  <tr>
                    <th class="authNo">序号</th>
                    <th class="authWeixinName">公众号名称</th>
                    <th class="authWeixinNum">开通子账号数量</th>
                    <th class="authPass">业务员、按揭员总人数</th>
                    <th class="authEMail">银行职员总人数</th>
                    <th class="authDate">授权日</th>
                    <th class='authURL'>授权地址</th>
                    <th class="authSetting">多选 <input type="checkbox" name="test" id="fuck" form='not_submit'></th>
                  </tr>
                </thead>
                <tbody>
                  <volist name='list' id='vo'>
                    <tr>
                      <th class="authNo">{$key+1}</th>
                      <th class="authWeixinName">{$vo.nick_name}</th>
                      <th class="authWeixinNum">{$vo.u_id|re_num_zi}</th>
                      <th class="authPass">{$vo.u_id|re_num_yj}</th>
                      <th class="authEMail">{$vo.u_id|re_num_yh}</th>
                      <th class="authDate">{$vo.date}</th>
                      <th class='authURL' title="<?php echo $_SERVER['SERVER_NAME']; ?>/{$vo.link}" inori-first="{:U('Home/Index/del_menu')}" inori-next="{:U('Home/Index/creat_menu')}" inori-id="{$vo.wechat_id}">授权地址</th>
                      <!-- <th name='wechat_id' style="display: none">{$vo.wechat_id}</th> -->
                      <th class="authSetting"><input type="checkbox" name="id_arr[]" id="diqu_3" form="delete_form" value="{$vo.wechat_id}"></th>

                    </tr>
                  </volist>
                </tbody>
              </table>
            <!-- end 授权地区列表列表 -->

            <!-- begin 删除选项（表单） -->
            <div class="form">
              <form autocomplete="off" action="{:U('index/diqu_weixin')}" id="delete_form" method="post">
                <input type="submit" value="删除所选" class="delete_all">
                <input type="reset" value="取消选择" class="reset_all">
              </form>
            </div>
            <!-- end 删除选项（表单） -->

            <!-- begin 分页 -->
            <div class="authPage">
                    <!-- 页面指示器 -->
                    <!-- <div class="pages">24/{$count}</div> -->
                    <!-- 分页列表 -->
                    <!-- <span class="number">...</span> -->
                    <div class="pageJump">{$page}</div>
            </div>
            <!-- end 分页 -->

          </div>
          <!-- end 右主体 -->

        </div>
      </div>
    </div>
  </div>
  <script>
    $('#add_local_frame').on('click', function(){
      layer.open({
        type: 2,
        title: 'layer mobile页',
        area: ['380px', '700px'],
        maxmin: true,
        content: "{:U('add_weixin')}" // 修改处 iframe的url
      })
    })
    $(document).ready(function() {
      $('.messageBoxContent thead .authSetting').on('click', function (event) {
        event.stopPropagation();Array.from($('.messageBoxContent input[type=\'checkbox\']')).forEach(function(val,index){val.checked = !val.checked})
      })
      var proList = $('#main_table').DataTable({
        "paging": false,
        "info": false,
        "searching": false
      })
    })
    window.addEventListener('message', fromNav, false)
    function fromNav(event) {
      console.log(event.data.url)
      if (event.data.url.length && event.data.url.length > 1) {
        self.location = event.data.url
      }
    }

    $(document).ready(() => {
      $('.authURL').each((index, item) => {
        if($(item).attr('title')) $(item).css('text -decoration', 'underline')
        if($(item).attr('title')) $(item).css('cursor', 'pointer')
        $(item).on('click', (evt) => {
          if($(evt.target).attr('title')) {
            let flagFirst = confirm('下一个弹窗中的URL需完整填写完毕后才能确定关闭，如输入URL失败请选择取消')
            if (flagFirst) {
              let flag = confirm($(evt.target).attr('title'))
              if (flag) {
                // inori-first="{:U('Home/Index/del_menu')}" inori-next
                const ajaxURL = $(evt.target).attr('inori-first')
                const ajaxURLNext = $(evt.target).attr('inori-next')
                const ajaxData = $(evt.target).attr('inori-id')
                $.ajax(ajaxURL, {
                  method: 'post',
                  data: {wechat_id: ajaxData}
                }).done((res) => {
                  if(String(res.code) === '1') {
                    $.ajax(ajaxURLNext, {
                      method: 'post',
                      data: {wechat_id: ajaxData}
                    }).fail((err) => {
                      alert('网络错误,请检查网络')
                    }).done((res) => {
                      if (String(res.code) === '1' && res.data) {
                        alert(`一键创建菜单完成`)
                        console.log(res.data)
                      } else {
                        alert(`请求失败：${res.message}`)
                      }
                    })
                  } else {
                    alert(`请求失败：${res.message}`)
                  }
                }).fail((err) => {
                  alert('网络错误,请检查网络')
                })
              }
            }
          }
        })
      })
    })
  </script>
</body>
</html>
